<template>
<div>
  <el-table
    v-if="hask"
    :data="tableData"
    stripe
    style="width: 100%">
    <el-table-column
      prop="brand_name"
      :label="label"
      width="180">
    </el-table-column>
    <el-table-column label="操作"  align="center">
        <template slot-scope="scope">
        <el-button
            size="mini"
            @click="updataShow(scope.$index, scope.row)">车系
        </el-button>
        <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除
        </el-button>
        </template>
    </el-table-column>
  </el-table>
  <el-table
    v-else
    :data="series"
    stripe
    style="width: 100%">
    <el-table-column
      prop="cars_name"
      :label="label"
      width="180">
    </el-table-column>
    <el-table-column label="操作"  align="center">
        <template slot-scope="scope">
        <el-button
            size="mini"
            @click="editDel(scope.index,scope.row)"
           >车型
        </el-button>
        <el-button
            size="mini"
            type="danger"
            @click="editDel(scope.index,scope.row)"
           >删除
        </el-button>
        </template>
    </el-table-column>
  </el-table>
</div>
</template>

<script>
  export default {
    props:['tableData','editTitle','label'],
    data() {
      return {
        series:null,
        hask:true
      }
    },
    methods: {
        updataShow(index,row){
          this.hask = false
            this.label = '型号'
            this.$http.get(this.GLOBAL.REQUESTURL +"/car/series/",{car_brand_id:row.id})
            .then( res =>{
                this.series = res
            })
        },
        handleDelete(index,row){
            console.log(row)
        },
        editDel(index,row){
          this.$confirm('是否要删除该品牌', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$http.deleteFn(this.GLOBAL.REQUESTURL +"/car/series/"+row.id+'/').then(response => {
              this.$message({
                message: '删除成功',
                type: 'success',
                duration: 1000
              });
              this.updataShow();
            });
          });                 
        }
    }
  }
</script>
